﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：角色添加	
 */
var acceptClick;
var auditorName = '';
var bootstrap = function ($, learun) {
    "use strict";

    var companyId = request("companyId");
    var departmentId = "";

    var page = {
        init: function () {
            page.bind();
        },
        bind: function () {
            $('#auditorId').lrselect({
                value: 'id',
                text: 'realName',
                title: 'realName',
                // 展开最大高度
                maxHeight: 110,
                // 是否允许搜索
                allowSearch: true,
                select: function (item) {
                    if (!!item) {
                        auditorName = item.realName;
                    }
                }
            });

            // 部门选择
           $('#department').lrselect({
               placeholder: '请选择部门',
               // 展开最大高度
               maxHeight: 100,
               // 是否允许搜索
               allowSearch: true
           });

           $('#companyId').lrselect({
               type: 'tree',
               placeholder: '请选择机构',
               url: config.base_server() + 'companys/tree?access_token=' + config.getToken().access_token,
               height: 300,
               maxHeight: 300,
               // 是否允许搜索
               allowSearch: true,
               select: function (company) {
                   if (!company || company.value == '-1') {
                       companyId = '';
                   } else {
                       companyId = company.value;
                       $('#department').lrselectRefresh({
                           // 访问数据接口地址
                           url: config.base_server() + 'departments/tree?access_token=' + config.getToken().access_token,
                           // 访问数据接口参数
                           param: {companyId: companyId, parentId: '0'},
                           select: function (department) {
                              if (!department || department.value == '-1') {
                                  departmentId = '';
                              } else {
                                  departmentId = department.value;
                                  $('#auditorId').lrselectRefresh({
                                     url: config.base_server() + 'users/list?access_token=' + config.getToken().access_token,
                                     param: {companyId: companyId, departmentId: departmentId}
                                  });
                              }
                           }
                       }).lrselectSetFirst();
                   }
               }
           }).lrselectSet(companyId);
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        var formData = $('#form').lrGetFormData();
        formData.auditorName = auditorName;
        formData.type = '3';//审核者类型1.岗位2.角色3.用户
        callBack(formData);
        return true;
    };
    page.init();
}